

#pragma once


class Object
{
public:
    Object() {};
    virtual ~Object() {}
};

class ObjectFactory {
public:
    ObjectFactory() {}
    virtual ~ObjectFactory();

    static Object* createByClassName(const char * name); 

protected:
    void reg(const char * name);
    void unreg();

private:
    virtual Object* doCreate() = 0;
};


#define REGISTER_CLASS_CREATOR(classname) \
    class classname ## Factory : public ObjectFactory \
    { \
    public: \
            classname ## Factory() { reg(#classname); } \
        virtual Object* doCreate() { return new classname(); } \
    }; \
    static classname ## Factory    classname ## CreatorFactory;

